// @ts-nocheck
/**
 * @Date: 2022-04-06 14:52:27
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-04-19 19:12:30
 * @FilePath: \weibo-api\db\seq.js
 * @Description: sequelize实例
 */
const { Sequelize } = require("sequelize");
const { MYSQL_CONF } = require("../conf/db");
const { host, user, password, database } = MYSQL_CONF;

const conf = {
  host: host,
  dialect: "mysql",
  logging: false,
};
const env = process.env.NODE_ENV;
//线上使用连接池
if (env === "production") {
  conf.pool = {
    max: 5, //最大连接数量
    min: 0,
    idle: 10000, //连接10s内没被使用就释放
  };
}
const sequelize = new Sequelize(database, user, password, conf);
// 连接测试;
// async function con() {
//   try {
//     await sequelize.authenticate();
//     console.log("sequlize连接成功");
//   } catch (error) {
//     console.error("sequlize连接失败，原因:", error);
//   }
// }
// con();
module.exports = sequelize;
